from app.MySQLDatabase import MySQLDatabase

class config_service:

    def selectByKey(config_name):
        db = MySQLDatabase()
        conn = db.connect()
        if conn:
            cursor = conn.cursor()
            sql = "select config_name,config_value,remark from dynamic_config where config_name = %s"
            data = (config_name,)
            cursor.execute(sql, data)
            result = cursor.fetchone()
            conn.commit()
            cursor.close()
            conn.close()
            return result
        
    def updateByKey(config_name, config_value):
        db = MySQLDatabase()
        conn = db.connect()
        if conn:
            cursor = conn.cursor()
            sql = "update dynamic_config set config_value = %s where config_name = %s"
            data = (config_value, config_name,)
            cursor.execute(sql, data)
            conn.commit()
            cursor.close()
            conn.close()